package cn.italobing.mybatis.text;

import java.io.IOException;

import org.apache.ibatis.session.SqlSession;
import org.junit.Assert;
import org.junit.Test;

import cn.itlaobing.entity.Teacher;
import cn.itlaobing.mapper.TeacherMapper;

public class TeacherMapperText  extends BaseMapperText{

	@Test
	public void findById() throws IOException {
		SqlSession sqlSession=sqlSession();
		try {
			TeacherMapper teacherMapper =sqlSession.getMapper(TeacherMapper.class);
			Teacher teacher =teacherMapper.selectByPrimaryKey(1L);
			Assert.assertNotNull(teacher);
			Assert.assertEquals("张三", teacher.getName());
		} finally {
			sqlSession.close();
		}
		
	}
	
	@Test
	public void insert() throws IOException {
		SqlSession sqlSession=sqlSession();
		try {
			TeacherMapper teacherMapper =sqlSession.getMapper(TeacherMapper.class);
			Teacher teacher =new Teacher();
			teacher.setName("李四");
			teacher.setAge(20);
			teacher.setGender("Male");
			
			teacherMapper.insert(teacher);
			
			sqlSession.commit();
			log.info(teacher.getId());
		} finally {
			sqlSession.close();
		}
		
	}
}
